package com.jinyi.wwdeng.utils.dialog

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
import com.jinyi.wwdeng.App
import com.jinyi.wwdeng.R
import com.jinyi.wwdeng.databinding.DialogBindCardSubmitBinding
import com.jinyi.wwdeng.databinding.IncludeConfirmerMobileBinding

/**
 * Author : wwdeng
 * Date : 2023/8/1 15:44
 * <p>
 * 每天进步一点点
 * <p>
 * Desc : 绑卡确认dialog
 */
class BindCardSubmitDialog: ProDialog {
    private lateinit var binding: DialogBindCardSubmitBinding
    private var mCallback: IDialogCallback? = null

    constructor(context: Context?) : super(context) {}
    constructor(context: Context?, callback: IDialogCallback?) : super(context) {
        mCallback = callback
    }

    /**
     * 设置点击回调
     */
    fun setOnClick(callback: IDialogCallback){
        this.mCallback = callback
    }

    override fun getRootView(): View {
        binding = DialogBindCardSubmitBinding.inflate(LayoutInflater.from(context))
        return binding.root
    }

    override fun initView() {
    }

    override fun initListener() {
        setOnClickListener(R.id.ivClose) //关闭
        setOnClickListener(R.id.btnConfirm)
    }

    override fun initData() {
        binding.cardLayout.removeAllViews()
        for (i in 0..1){
            val itemBinding = IncludeConfirmerMobileBinding.inflate(LayoutInflater.from(context))
            itemBinding.btnDelete.visibility = View.GONE
            val cardItemView = itemBinding.root
            val layoutParams = LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT)
            layoutParams.topMargin = App.dp2px(12f)
            layoutParams.height = App.dp2px(86f)
            cardItemView.layoutParams = layoutParams
            binding.cardLayout.addView(cardItemView)
        }
    }

    override fun onViewClick(v: View?) {
        dismiss()
        if(mCallback != null){
            mCallback!!.onClick(v)
        }
    }

    interface IDialogCallback {
        //按钮点击
        fun onClick(view: View?)
    }
}